package cn.gzsxt.mapper;

import java.util.List;
import java.util.Map;

import org.apache.ibatis.annotations.DeleteProvider;
import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Options;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.SelectProvider;
import org.apache.ibatis.annotations.UpdateProvider;

import cn.gzsxt.mapper.provider.ModularProvider;

@Mapper
public interface ModularMapper {

	/**
	 * 通过条件返回总记录数
	 * 
	 * @param condition
	 * @return
	 */
	@SelectProvider(type = ModularProvider.class, method = "count")
	long count(Map<String, Object> condition);
	
	/**
	 * 通过编号删除记录
	 * @param modularIds
	 * @return
	 */
	@DeleteProvider(type=ModularProvider.class,method="deleteByIds")
	int deleteByIds(Object... modularIds);

	/**
	 * 查询所有模块数据
	 * 
	 * @return
	 */
	@Select("SELECT * FROM tb_basic_modular")
	List<Map<String, Object>> findAll();

	/**
	 * 通过条件分页查询
	 * 
	 * @param condition
	 * @param start
	 *            = index * size （数据库索引从0开始）
	 * @param size
	 * @return
	 */
	@SelectProvider(type = ModularProvider.class, method = "findByConditionAndPage")
	List<Map<String, Object>> findByConditionAndPage(@Param("condition") Map<String, Object> condition,
			@Param("start") int start, @Param("size") int size);

	/**
	 * 通过模块编号查询一条记录
	 * @param modularId
	 * @return
	 */
	@Select("SELECT *	FROM tb_basic_modular WHERE MODULAR_ID=#{modularId}")
	Map<String,Object> findById(Object modularId);
	
	/**
	 * 插入模块记录
	 * 
	 * @param modular
	 * @return
	 */
	@Insert("INSERT INTO tb_basic_modular	(MODULAR_NAME, MODULAR_SORT) VALUES (#{MODULAR_NAME}, #{MODULAR_SORT})")
	@Options(useGeneratedKeys = true, keyProperty = "MODULAR_ID")
	int insert(Map<String, Object> modular);
	
	/**
	 * 更新模块非空的字段
	 * @param admin
	 * @return
	 */
	@UpdateProvider(type=ModularProvider.class,method="updateForNotnull")
	int updateForNotnull(Map<String, Object> modular);

}
